home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / serisamp.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  5KB  |  175 lines

  1. /* serial sample program v28 */
  2. /****************************************************************
  3. *                                                               *
  4. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  5. * No part of this program may be reproduced, transmitted,       *
  6. * transcribed, stored in retrieval system, or translated into   *
  7. * any language or computer language, in any form or by any      *
  8. * means, electronic, mechanical, magnetic, optical, chemical,   *
  9. * manual or otherwise, without the prior written permission of  *
  10. * Commodore Amiga Incorporated, 983 University Avenue #D        *
  11. * Los Gatos, CA 95030                                           *
  12. *                                                               *
  13. ****************************************************************/
  14.  
  15. #define SERPORTEVENTS
  16.  
  17.  
  18. #include        "exec/types.h"
  19. #include        "exec/nodes.h"
  20. #include        "exec/lists.h"
  21. #include        "exec/memory.h"
  22. #include        "exec/ports.h"
  23. #include        "exec/libraries.h"
  24. #include        "exec/devices.h"
  25. #include        "exec/tasks.h"
  26. #include        "exec/io.h"
  27. #include        "exec/interrupts.h"
  28. #include        "devices/timer.h"
  29. #include        "devices/inputevent.h"
  30. #include        "serial.h"
  31.  
  32. struct IOExtSer IORser;
  33. struct MsgPort *port;
  34. char   buffer[100];
  35. extern struct MsgPort *CreatePort();
  36.  
  37. main()
  38. {
  39.     int     error;
  40.     int     actual;
  41.     unsigned char iof;
  42.     unsigned long cc;
  43.     unsigned long rbl;
  44.     unsigned long wbl;
  45.     unsigned long brk;
  46.     unsigned long baud;
  47.     unsigned char rwl;
  48.     unsigned char wwl;
  49.     unsigned char sf;
  50.     unsigned long t0;
  51.     unsigned long t1;
  52.  
  53. open:
  54.  /* OPEN the serial.device */
  55.     if ((error = OpenDevice (SERIALNAME, 0, &IORser, 0)) != 0) {
  56.         write ("bad news on Open\n",-1);
  57.         exit (error);
  58.     }
  59.  
  60.  /* SET UP the read message port in the I/O request */
  61.     port = CreatePort (SERIALNAME,0);
  62.     IORser.IOSer.io_Message.mn_ReplyPort = port;
  63.  
  64.     write ("\n\015opened ok\n\015", -1);
  65.  
  66.  
  67. /*    SET PARAMS for the serial.device
  68.     iof = 0x00;
  69.     cc  = 0x00;
  70.     rbl = 4096;
  71.     wbl = 4096;
  72.     rwl = 0x08;
  73.     wwl = 0x08;
  74.     brk = 250000;
  75.     baud= 9600;
  76.     sf  = 0x04;
  77.     t0  = 0x51515151;
  78.     t1  = 0x04040404;
  79.  
  80.   if ((error = setparams (iof,cc,rbl,wbl,rwl,wwl,brk,baud,sf,t0,t1)) != 0) {
  81.         write ("bad news on setup \n\015", -1);
  82.         exit (error);
  83.     } */
  84.  
  85.     write ("test of -1 length\n\015", -1);
  86.     write ("\n\015test of -1 length garbage till term7XXXXX", 43);
  87.     write ("\n\015test of -1 length garbage till term6XXXXX", 43);
  88.     actual = read (buffer,16);
  89.     write ("\n\015Buffer was :\n\015", -1); 
  90.     write (buffer, actual); 
  91.     write ("\n\015end\n\015", -1);
  92.  
  93.  /* CLOSE the serial.device */
  94.     if ((error = CloseDevice (&IORser)) != 0) {
  95.         write ("bad news on Close\n",-1);
  96.         exit (error);
  97.     }
  98.  
  99.     Debug (0);
  100. }
  101.  
  102. setparams(is,ctl_char,rbuf_len,wbuf_len,rlen,wlen,brk,baud,sf,ta0,ta1)
  103.  
  104.     unsigned char is;
  105.     unsigned long ctl_char;
  106.     unsigned long rbuf_len;
  107.     unsigned long wbuf_len;
  108.     unsigned char rlen;
  109.     unsigned char wlen;
  110.     unsigned long brk;
  111.     unsigned long baud;
  112.     unsigned char sf;
  113.     unsigned long ta0;
  114.     unsigned long ta1;
  115.  
  116. {
  117.     int error;
  118.  
  119.     IORser.IOSer.io_Flags   = is;
  120.     IORser.io_CtlChar       = ctl_char;
  121.     IORser.io_ReadLen       = rlen;
  122.     IORser.io_BrkTime       = brk;
  123.     IORser.io_Baud          = baud;
  124.     IORser.io_WriteLen      = wlen;
  125.     IORser.io_StopBits      = 0x01;
  126.     IORser.io_RBufLen       = rbuf_len;
  127.     IORser.io_WBufLen       = wbuf_len;
  128.     IORser.io_SerFlags      = sf;
  129.     IORser.IOSer.io_Command = SDCMD_SETPARAMS;
  130.     IORser.io_TermArray.TermArray0 = ta0;
  131.     IORser.io_TermArray.TermArray1 = ta1;
  132.  
  133.     if ((error = DoIO (&IORser)) != 0) {
  134.         write ("setp error\n", -1);
  135.         exit (1);
  136.     }
  137.     return (error);
  138. }
  139.  
  140. read(data,length)
  141.     char *data;
  142.     ULONG length;
  143. {
  144.     int error;
  145.  
  146.     IORser.IOSer.io_Data = data;
  147.     IORser.IOSer.io_Length = length;
  148.     IORser.IOSer.io_Command = CMD_READ;
  149.  
  150.     if ((error = DoIO (&IORser)) != 0) {
  151.         write ("read error\n", -1);
  152.         exit (1);
  153.     }
  154.     return (IORser.IOSer.io_Actual);
  155. }
  156.  
  157.  
  158. write(data,length)
  159.     char *data;
  160.     int length;
  161. {
  162.     int     error;
  163.  
  164.     IORser.IOSer.io_Data = data;
  165.     IORser.IOSer.io_Length = length;
  166.     IORser.IOSer.io_Command = CMD_WRITE;
  167.  
  168.     if ((error = DoIO (&IORser)) != 0) {
  169.         write ("serial.device write error\n", -1);
  170.         /* ShowIORequest (&IORser); */
  171.         exit (1);
  172.     }
  173.     return (IORser.IOSer.io_Actual);
  174. }
  175.